<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>懒加载1</title>
</head>
<style>
    .box{
        width:100px;
        height:100px;
        background-color:orange;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
    };
</style>
<body>
    <div class="box" draggable="true"></div>
    
    <script>
        /*
            scrollTop 和 offsetTop
        */ 

        const bnt = document.getElementsByClassName('box')[0];


        function inInViewWindow(element) {
            // 兼容各种浏览器的写法
            const viewPortHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;  // 视窗高度
            const offsetTop = element.offsetTop;   // 获取偏移top
            const scrollTop = document.documentElement.scrollTop;   // 
            const top = offsetTop - scrollTop; 
            return top <= viewPortHeight;
        };
        

        console.log(inInViewWindow(bnt));  // true

        
    </script>
</body>
</html>